<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../../vue.js"></script>
  <script src="../../vue-router.js"></script>

  <style>
    .active {
      font-weight: 500;
      color: red;
    }
  </style>
</head>

<body>

  <div id="app">

    <ul>
      <router-link tag="li" to="/" exact active-class="active">首页</router-link>
      <router-link tag="li" to="/position/35" active-class="active">职位</router-link>
      <router-link tag="li" to="/search?keyword=前端" active-class="active">搜索</router-link>
    </ul>
    <router-view></router-view>
  </div>

  <script>
    const position = {
      props: ['id', 'username', 'age'],
      template: `<div>postion- {{username}}-{{age}}-{{$route.params.id}}</div>`
    }

    const search = {
      props: ['query'],
      template: `<div>search-{{query}}</div>`
    }



    var router = new VueRouter({
      // mode: 'history',
      routes: [
        {
          path: '/position/:id',
          component: position,
          props: { username: 'hanye', age: 20 }
        },
        {
          path: '/search',
          component: search,
          props: (route) => ({ query: route.query.keyword })
        }
      ]
    })

    var vm = new Vue({
      router,
      el: '#app'
    })

  </script>

</body>

</html>